using System.IO;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace CodeStory.WebControls
{
	/// <summary>
	/// 
	/// </summary>
	public class ComboBoxDesigner : ControlDesigner
	{
		private ComboBox comboBox;

		public ComboBoxDesigner() {
		}

		public override void Initialize(System.ComponentModel.IComponent component) {
			base.Initialize(component);
			this.comboBox = (ComboBox)component;
		}

		public override string GetDesignTimeHtml() {
			DropDownList drop = new DropDownList();
			if (this.comboBox.Items.Count > 0) {
				foreach (ComboItem item in comboBox.Items) {
					ListItem litem = new ListItem(item.Text, item.Text);
					if (item.Selected) {
						litem.Selected = true;
					}
					drop.Items.Add(litem);
				}
			} else {
				drop.Items.Add(new ListItem("Unbound"));
			}
			drop.Width = comboBox.Width;
			StringWriter sw = new StringWriter();
			HtmlTextWriter tw = new HtmlTextWriter(sw);
			drop.RenderControl(tw);
			return sw.ToString();
		}
	}
}